package Service;

import java.util.ArrayList;
import java.util.HashMap;

import javax.annotation.Resource;

import me.gacl.domain.Team;

import org.springframework.stereotype.Service;

import Dao.TeamDao;
import Dao.DaoImp;

@Service("teamService")
public class ServiceImp implements TeamService {
	// private DaoImp DaoImp = new DaoImp();
	// private DaoImp DaoImp;
	@Resource(name = "teamDao")
	private TeamDao TeamDao;

	public void setTeamDao(TeamDao teamDao) {
		TeamDao = teamDao;
	}

	// ��ѯ���
	public String showTeam(String teamname, String teamnumber, String pagenow,
			String pagesize) {

		int PageNow = Integer.parseInt(pagenow);
		int PageSize = Integer.parseInt(pagesize);

		int from = PageSize * (PageNow - 1);
		int to = PageSize;

		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put("teamname", teamname);
		map.put("teamnumber", teamnumber);
		map.put("from", from);
		map.put("to", to);

		String ListTeam = TeamDao.pagesplit(map);

		return ListTeam;
	}

	// ������
	public int addTeam(String teamname, String teamnumber) {

		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put("teamname", teamname);
		map.put("teamnumber", teamnumber);

		int flag = TeamDao.add(map);

		return flag;
	}

	// ɾ�����
	public int destroyTeam(String teamname) {

		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put("teamname", teamname);
		int flag = TeamDao.destroy(map);

		return flag;
	}

	// �༭���
	public int editTeam(String teamnameold, String teamnamenew,
			String teamnumber) {

		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put("teamnamenew", teamnamenew);
		map.put("teamnumber", teamnumber);
		map.put("teamnameold", teamnameold);
		int flag = TeamDao.edit(map);
		System.out.println(flag);
		return flag;
	}

	public String searchTeam(String teamname, String teamnumber,
			String pagenow, String pagesize) {

		int PageNow = Integer.parseInt(pagenow);
		int PageSize = Integer.parseInt(pagesize);

		int from = PageSize * (PageNow - 1);
		int to = PageSize;

		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put("teamname", teamname);
		map.put("teamnumber", teamnumber);
		map.put("from", from);
		map.put("to", to);

		HashMap<String, String> toge = TeamDao.searchTeam(map);
		String ListTeam = toge.get("searchlist");
		String rowcount = toge.get("rowcount");
		System.out.println("��������������  rowcount "+rowcount);
		if ((teamname.equals("")) && (teamnumber.equals(""))) {
			return null;
		} else if (rowcount.equals("0")) {
			return null;
		} else {
			return ListTeam;
		}
	}

	public TeamDao getTeamDao() {
		return TeamDao;
	}

	

	// ������Bean�󣬽�TeamDao��עͨ��Service������TeamDaoע��TeamDaoService

	// ��֤���
	public int signTeam(String team, String number) {

		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put("team", team);
		map.put("number", number);
		System.out.println("Service: "+team);
		System.out.println("Service: "+number);

		int flag = TeamDao.sign(map);

		return flag;
	}
	
	// ��֤���ʹ��teambean

	public int signexTeam(Team team) {

		int flag = TeamDao.signex(team);

		return flag;
	}

	@Override
	public String luanma(String team) {
		// TODO Auto-generated method stub
		HashMap<String, Object> map = new HashMap<String, Object>();
		map.put("team", team);
		String flag = TeamDao.luanma(map);
		return flag;
	}

}

/*
 * public String pagesplit(HashMap<String, Object> map1,HashMap<String, Object>
 * map2) { String statement1 = "me.gacl.mapping.userMapper.filterlist"; String
 * statement2 = "me.gacl.mapping.userMapper.count_filter"; ArrayList<Object>
 * list0= teamdao.result(statement1, map1); int RowCount =
 * teamdao.Rowcount(statement2, map2); String
 * list="{\"total\" : "+RowCount+", \"rows\" : "+list0+"}"; return list; }
 */

